package ca.uwindsor.cs.deepweb.estimation.method.border;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import ca.uwindsor.cs.deepweb.estimation.RandomWordSelector;
import ca.uwindsor.cs.deepweb.estimation.experiment.service.QueryService;

public class QueryRunnerWordsAll {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		if(args.length!=6){
			System.out.println("java QueryRunnerWords wordlist.txt index outputfile");
			System.exit(-1);
		}
		ArrayList<String> words = new ArrayList<String>();
		RandomWordSelector selector = new RandomWordSelector(args[0], "UTF-8");

		int wordsquantity = Integer.parseInt(args[2]);
		for (int i = 0; i < wordsquantity; i++) {
			words.add(selector.getRandomPhrase());
		}
		String[] wl = words.toArray(new String[words.size()]);
		QueryService qs = new QueryService(args[1], new Integer(args[4]), wl, new Integer(args[5]),
				null, false);

		try {
			qs.setStepSize(new Integer(args[5]));
			// qs.setOuputDocumentUniqueTerms(indexdir)
			qs.setOutputDocumentCaptureFrequencyDistribution(false);
			// qs.setOuputDocumentUniqueAndTotalTerms(
			// "F:\\DocumentNumberofUniqueTotalTermsIndex\\GOV2_doc_terms_unique_total\\0"
			// );
			qs.setOutputORmethodResult(true);
			qs.setOutputDocumentFrequency(false);
			qs.setOutputDocumentSize(false);
			qs.setOutputDocumentSizeDistribution(false);
			qs.setOutputTermWeightandNumberofDocument(false);
			qs.setOutputTermWeightDistribution(false);
			qs.setOutputDocumentWeight(false);
			String result = qs.goQuery();

			System.out.println(result);
			FileOutputStream fp;
			fp = new FileOutputStream(args[3]);
			fp.write(result.getBytes("UTF-8"));
			fp.flush();
			fp.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
